// 按需加载 ECharts，通过函数调用（API 方式）获取实例
// 借助精简注册版本（echarts-lite）
let _echarts = null

export async function getECharts() {
    if (_echarts) return _echarts
    const mod = await import('./echarts-lite')
    _echarts = mod.echarts
    return _echarts
}

export async function createChart(dom, baseOption) {
    const echarts = await getECharts()
    const instance = echarts.init(dom)
    if (baseOption) instance.setOption(baseOption)
    return instance
}

export function setChartOption(instance, option) {
    if (instance && option) instance.setOption(option)
}

export function disposeChart(instance) {
    if (instance) instance.dispose()
}
